<?php

/**
 * comment actions.
 *
 * @package    iEasy
 * @subpackage comment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class commentActions extends adminBase
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
      $this->recordCount = $request->getParameter('recordCount');
      $this->currentPage = $request->getParameter('currentPage');
      $submitType = $request->getParameter("submitType");
      if($submitType != null)
      {
          $content=$request->getParameter("content");
          if(!empty($content))
          {
              $Ids=explode(" ",$content);
              for($i=0;$i<count($Ids);$i++)
              {
                  if(!empty($Ids[$i]))
                  {
                      $currentComment=@Doctrine_Core::getTable('comment')->find($Ids[$i]);
                      if(!empty($currentComment))
                      {
                          $currentComment->setModifyTime(date("Y-m-d H:i:s"));
                          switch($submitType)
                          {
                              case "delete": //
                                  $currentComment->setStatusId(1006);
                                  break;
                              case "publish":
                                  if($currentComment->getStatusId() != 1005)
                                  {
                                      $currentComment->setStatusId(1005); //
                                  }
                                  break;
                              case "cancelPublish":
                                  $currentComment->setStatusId(1004); //不审核
                                  break;
                          }
                          @$currentComment->save();
                      }
                  }
              }
          }
      }

      if (null == $this->recordCount || "" == $this->recordCount)
          $this->recordCount =20;
      if (null == $this->currentPage || "" == $this->currentPage)
          $this->currentPage = 1;

      $this->navigator="用户评论管理 -> 美图";
      $query = Doctrine_Query::create()->from("Comment c")->where('c.content_type_i=1003');//->orderBy('c.comment_id desc');
      $this->searchProperty = $request->getParameter("searchProperty");
      switch($this->searchProperty)
      {
          case "unexamined":
              $query = $query->andWhere("c.status_id=1004");
              break;
          case "publish":
              $query = $query->andWhere("c.status_id=1005");
              break;
          case "delete":
              $query = $query->andWhere("c.status_id=1006");
              break;
      }
      $this->searchField = $request->getParameter("searchField");
      $this->searchText = trim($request->getParameter("searchText"));
      switch($this->searchField)
      {

          case "titles":
              $phos = Doctrine_Query::create()->from("PhotoGroup")->where("title like ?","%".$this->searchText."%")->execute();
              $pids="";
              $num=0;
              foreach($phos as $pho)
              {
                  if($num!=0)
                      $pids.=",";
                  $pids.=$pho->getPhotoGroupId();
                  $num++;
              }
              if(!empty($pids))
                  $query = $query->andWhere("content_id in (".$pids.")");
              else
                  $query = $query->andWhere("1=2");
              break;
          case "bodys":
              $query = $query->andWhere("body like ?","%".$this->searchText."%");
              break;
          case "name":
              $users = Doctrine_Query::create()->from("Users u")->where("name like ?","%".$this->searchText."%")->execute();
              $uids="";
              $num=0;
              foreach($users as $user)
              {
                  if($num!=0)
                      $uids.=",";
                  $uids.=$user->getUserId();
                  $num++;
              }
              if(!empty($uids))
                  $query = $query->andWhere("user_id in (".$uids.")");
              else
                  $query = $query->andWhere("1=2");
              break;
          case "tid":
              if(!empty($this->searchText))
                  $query = $query->andWhere("content_id = ?",$this->searchText);
              break;
          case "cid":
              if(!empty($this->searchText))
                  $query = $query->andWhere("comment_id = ?",$this->searchText);
              break;
      }
      $query=$query->orderBy('c.comment_id desc');
      $this->pages = new sfDoctrinePager('Comment',$this->recordCount); //$this->currentPage
      $this->pages->setQuery($query); //$q   数据库查询语句
      $this->pages->setPage($this->currentPage); //
      $this->pages->init();
  }
    
    public function executeEdit(sfWebRequest $request) {
        $this->contEdit=$request->getParameter("contentEdit");
        switch($this->contEdit){
            case "1":
                $this->comment=@Doctrine_Core::getTable('comment')->find($request->getParameter("content"));
                break;
            case "2":
                $comment=@Doctrine_Core::getTable('comment')->find($request->getParameter("content"));
                $comment->setBody($request->getParameter("bodys"));
                $comment->setModifyTime(date("Y-m-d H:i:s"));
                $comment->save();
                break;
        }
    }
    
    public function executeIndexa(sfWebRequest $request) {//美图
      $this->recordCount = $request->getParameter('recordCount');
      $this->currentPage = $request->getParameter('currentPage');
      $submitType = $request->getParameter("submitType");
      if($submitType != null)
      {
          $content=$request->getParameter("content");
          if(!empty($content))
          {
              $Ids=explode(" ",$content);
              for($i=0;$i<count($Ids);$i++)
              {
                  if(!empty($Ids[$i]))
                  {
                      $currentComment=@Doctrine_Core::getTable('comment')->find($Ids[$i]);
                      if(!empty($currentComment))
                      {
                          $currentComment->setModifyTime(date("Y-m-d H:i:s"));
                          switch($submitType)
                          {
                              case "delete": //
                                  $currentComment->setStatusId(1006);
                                  break;
                              case "publish":
                                  if($currentComment->getStatusId() != 1005)
                                  {
                                      $currentComment->setStatusId(1005); //
                                  }
                                  break;
                              case "cancelPublish":
                                  $currentComment->setStatusId(1004); //不审核
                                  break;
                          }
                          @$currentComment->save();
                      }
                  }
              }
          }
      }

      if (null == $this->recordCount || "" == $this->recordCount)
          $this->recordCount =20;
      if (null == $this->currentPage || "" == $this->currentPage)
          $this->currentPage = 1;

      $this->navigator="用户评论管理 -> 美图";
      $query = Doctrine_Query::create()->from("Comment c")->where('c.content_type_i=1003');
      $this->searchProperty = $request->getParameter("searchProperty");
      switch($this->searchProperty)
      {
          case "unexamined":
              $query = $query->andWhere("c.status_id=1004");
              break;
          case "publish":
              $query = $query->andWhere("c.status_id=1005");
              break;
          case "delete":
              $query = $query->andWhere("c.status_id=1006");
              break;
      }
      $this->searchField = $request->getParameter("searchField");
      $this->searchText = trim($request->getParameter("searchText"));
      switch($this->searchField)
      {

          case "titles":
              $phos = Doctrine_Query::create()->from("PhotoGroup")->where("title like ?","%".$this->searchText."%")->execute();
              $pids="";
              $num=0;
              foreach($phos as $pho)
              {
                  if($num!=0)
                      $pids.=",";
                  $pids.=$pho->getPhotoGroupId();
                  $num++;
              }
              if(!empty($pids))
                  $query = $query->andWhere("content_id in (".$pids.")");
              else
                  $query = $query->andWhere("1=2");
              break;
          case "bodys":
              $query = $query->andWhere("body like ?","%".$this->searchText."%");
              break;
          case "name":
              $users = Doctrine_Query::create()->from("Users u")->where("name like ?","%".$this->searchText."%")->execute();
              $uids="";
              $num=0;
              foreach($users as $user)
              {
                  if($num!=0)
                      $uids.=",";
                  $uids.=$user->getUserId();
                  $num++;
              }
              if(!empty($uids))
                  $query = $query->andWhere("user_id in (".$uids.")");
              else
                  $query = $query->andWhere("1=2");
              break;
          case "tid":
              if(!empty($this->searchText))
                  $query = $query->andWhere("content_id = ?",$this->searchText);
              break;
          case "cid":
              if(!empty($this->searchText))
                  $query = $query->andWhere("comment_id = ?",$this->searchText);
              break;
      }
      $query=$query->orderBy('c.comment_id desc');
      $this->pages = new sfDoctrinePager('Comment',$this->recordCount); //$this->currentPage
      $this->pages->setQuery($query); //$q   数据库查询语句
      $this->pages->setPage($this->currentPage); //
      $this->pages->init();
    }

    public function executeIndexn(sfWebRequest $request) {//新闻
        $this->recordCount = $request->getParameter('recordCount');
        $this->currentPage = $request->getParameter('currentPage');
        $submitType = $request->getParameter("submitType");
        if($submitType != null)
        {
            $content=$request->getParameter("content");
            if(!empty($content))
            {
                $Ids=explode(" ",$content);
                for($i=0;$i<count($Ids);$i++)
                {
                    if(!empty($Ids[$i]))
                    {
                        $currentComment=@Doctrine_Core::getTable('comment')->find($Ids[$i]);
                        if(!empty($currentComment))
                        {
                            $currentComment->setModifyTime(date("Y-m-d H:i:s"));
                            switch($submitType)
                            {
                                case "delete": //
                                    $currentComment->setStatusId(1006);
                                    break;
                                case "publish":
                                    if($currentComment->getStatusId() != 1005)
                                    {
                                        $currentComment->setStatusId(1005); //
                                    }
                                    break;
                                case "cancelPublish":
                                    $currentComment->setStatusId(1004); //不审核
                                    break;
                            }
                            @$currentComment->save();
                        }
                    }
                }
            }
        }

        if (null == $this->recordCount || "" == $this->recordCount)
            $this->recordCount =20;
        if (null == $this->currentPage || "" == $this->currentPage)
            $this->currentPage = 1;

        $this->navigator="用户评论管理 -> 新闻";
        $query = Doctrine_Query::create()->from("Comment c")->where('c.content_type_i=1000');
        $this->searchProperty = $request->getParameter("searchProperty");
        switch($this->searchProperty)
        {
            case "unexamined":
                $query = $query->andWhere("c.status_id=1004");
                break;
            case "publish":
                $query = $query->andWhere("c.status_id=1005");
                break;
            case "delete":
                $query = $query->andWhere("c.status_id=1006");
                break;
        }
        $this->searchField = $request->getParameter("searchField");
        $this->searchText = trim($request->getParameter("searchText"));
        switch($this->searchField)
        {

            case "titles":
                $phos = Doctrine_Query::create()->from("PhotoGroup")->where("title like ?","%".$this->searchText."%")->execute();
                $pids="";
                $num=0;
                foreach($phos as $pho)
                {
                    if($num!=0)
                        $pids.=",";
                    $pids.=$pho->getPhotoGroupId();
                    $num++;
                }
                if(!empty($pids))
                    $query = $query->andWhere("content_id in (".$pids.")");
                else
                    $query = $query->andWhere("1=2");
                break;
            case "bodys":
                $query = $query->andWhere("body like ?","%".$this->searchText."%");
                break;
            case "name":
                $users = Doctrine_Query::create()->from("Users u")->where("name like ?","%".$this->searchText."%")->execute();
                $uids="";
                $num=0;
                foreach($users as $user)
                {
                    if($num!=0)
                        $uids.=",";
                    $uids.=$user->getUserId();
                    $num++;
                }
                if(!empty($uids))
                    $query = $query->andWhere("user_id in (".$uids.")");
                else
                    $query = $query->andWhere("1=2");
                break;
            case "tid":
                if(!empty($this->searchText))
                    $query = $query->andWhere("content_id = ?",$this->searchText);
                break;
            case "cid":
                if(!empty($this->searchText))
                    $query = $query->andWhere("comment_id = ?",$this->searchText);
                break;
        }
        $query=$query->orderBy('c.comment_id desc');
        $this->pages = new sfDoctrinePager('Comment',$this->recordCount); //$this->currentPage
        $this->pages->setQuery($query); //$q   数据库查询语句
        $this->pages->setPage($this->currentPage); //
        $this->pages->init();
    }

    public function executeIndexv(sfWebRequest $request) {//视频
        $this->recordCount = $request->getParameter('recordCount');
        $this->currentPage = $request->getParameter('currentPage');
        $submitType = $request->getParameter("submitType");
        if($submitType != null)
        {
            $content=$request->getParameter("content");
            if(!empty($content))
            {
                $Ids=explode(" ",$content);
                for($i=0;$i<count($Ids);$i++)
                {
                    if(!empty($Ids[$i]))
                    {
                        $currentComment=@Doctrine_Core::getTable('comment')->find($Ids[$i]);
                        if(!empty($currentComment))
                        {
                            $currentComment->setModifyTime(date("Y-m-d H:i:s"));
                            switch($submitType)
                            {
                                case "delete": //
                                    $currentComment->setStatusId(1006);
                                    break;
                                case "publish":
                                    if($currentComment->getStatusId() != 1005)
                                    {
                                        $currentComment->setStatusId(1005); //
                                    }
                                    break;
                                case "cancelPublish":
                                    $currentComment->setStatusId(1004); //不审核
                                    break;
                            }
                            @$currentComment->save();
                        }
                    }
                }
            }
        }

        if (null == $this->recordCount || "" == $this->recordCount)
            $this->recordCount =20;
        if (null == $this->currentPage || "" == $this->currentPage)
            $this->currentPage = 1;

        $this->navigator="用户评论管理 -> 视频";
        $query = Doctrine_Query::create()->from("Comment c")->where('c.content_type_i=1001');
        $this->searchProperty = $request->getParameter("searchProperty");
        switch($this->searchProperty)
        {
            case "unexamined":
                $query = $query->andWhere("c.status_id=1004");
                break;
            case "publish":
                $query = $query->andWhere("c.status_id=1005");
                break;
            case "delete":
                $query = $query->andWhere("c.status_id=1006");
                break;
        }
        $this->searchField = $request->getParameter("searchField");
        $this->searchText = trim($request->getParameter("searchText"));
        switch($this->searchField)
        {

            case "titles":
                $phos = Doctrine_Query::create()->from("PhotoGroup")->where("title like ?","%".$this->searchText."%")->execute();
                $pids="";
                $num=0;
                foreach($phos as $pho)
                {
                    if($num!=0)
                        $pids.=",";
                    $pids.=$pho->getPhotoGroupId();
                    $num++;
                }
                if(!empty($pids))
                    $query = $query->andWhere("content_id in (".$pids.")");
                else
                    $query = $query->andWhere("1=2");
                break;
            case "bodys":
                $query = $query->andWhere("body like ?","%".$this->searchText."%");
                break;
            case "name":
                $users = Doctrine_Query::create()->from("Users u")->where("name like ?","%".$this->searchText."%")->execute();
                $uids="";
                $num=0;
                foreach($users as $user)
                {
                    if($num!=0)
                        $uids.=",";
                    $uids.=$user->getUserId();
                    $num++;
                }
                if(!empty($uids))
                    $query = $query->andWhere("user_id in (".$uids.")");
                else
                    $query = $query->andWhere("1=2");
                break;
            case "tid":
                if(!empty($this->searchText))
                    $query = $query->andWhere("content_id = ?",$this->searchText);
                break;
            case "cid":
                if(!empty($this->searchText))
                    $query = $query->andWhere("comment_id = ?",$this->searchText);
                break;
        }
        $query=$query->orderBy('c.comment_id desc');
        $this->pages = new sfDoctrinePager('Comment',$this->recordCount); //$this->currentPage
        $this->pages->setQuery($query); //$q   数据库查询语句
        $this->pages->setPage($this->currentPage); //
        $this->pages->init();
    }

}
